home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 190H69I (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  1.7 KB  |  47 lines

  1. package com.sun.java.swing.text;
  2.  
  3. import com.sun.java.swing.JComponent;
  4. import java.awt.Component;
  5. import java.awt.Point;
  6. import java.awt.Rectangle;
  7. import java.awt.event.ActionEvent;
  8.  
  9. class DefaultEditorKit$PageUpAction extends TextAction {
  10.    DefaultEditorKit$PageUpAction() {
  11.       super("page-up");
  12.    }
  13.  
  14.    public void actionPerformed(ActionEvent e) {
  15.       JTextComponent target = ((TextAction)this).getTextComponent(e);
  16.       if (target != null) {
  17.          Rectangle visible = new Rectangle();
  18.          ((JComponent)target).computeVisibleRect(visible);
  19.          int scrollOffset = visible.y;
  20.          visible.y -= visible.height;
  21.          if (visible.y < 0) {
  22.             visible.y = 0;
  23.          }
  24.  
  25.          scrollOffset -= visible.y;
  26.          ((JComponent)target).scrollRectToVisible(visible);
  27.          int selectedIndex = target.getCaretPosition();
  28.  
  29.          try {
  30.             if (selectedIndex != -1) {
  31.                Rectangle r = target.modelToView(selectedIndex);
  32.                r.y -= scrollOffset;
  33.                selectedIndex = target.viewToModel(new Point(r.x, r.y));
  34.                if (selectedIndex < 0) {
  35.                   selectedIndex = 0;
  36.                }
  37.  
  38.                target.setCaretPosition(selectedIndex);
  39.             }
  40.          } catch (BadLocationException var7) {
  41.             ((Component)target).getToolkit().beep();
  42.          }
  43.       }
  44.  
  45.    }
  46. }
  47.